package demo07;

import java.time.*;

/**
 * @author: WangPeng
 * @createTime: 2022/11/07 17:28
 * @description:
 * @version: v1.0
 */
public class Test03 {
    public static void main(String[] args) {
    //日期的时间差--Period.between()
        LocalDate localDate = LocalDate.of(2019, 9, 1);
        LocalDate now = LocalDate.now();
        Period period = Period.between(localDate,now);
        System.out.println("相差的年份："+period.getYears());
        System.out.println("相差的月份："+period.getMonths());
        System.out.println("相差的天数："+period.getDays());
        //在原有的时间差加上指定时间
        int plusMonths = period.plusMonths(2).getMonths();
        System.out.println("相差的月份："+period.plusMonths(2).getMonths());
        //在原有的时间差减去指定时间
        Period minusMonths = period.minusMonths(2);
        System.out.println("相差的月份："+ period.minusMonths(2).getMonths());
    //时间的时间差--Duration.between()
        LocalTime localTime = LocalTime.of(13, 13, 13);
        LocalTime now1 = LocalTime.now();
        Duration duration = Duration.between(localTime, now1);
        System.out.println("相差的小时："+duration.toHours());
        System.out.println("相差的分钟："+duration.toMinutes());
        System.out.println("相差的秒数："+duration.getSeconds());
    }
}
